package com.heima.wemedia.feign;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.apis.wemedia.IWemediaClient;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmUser;
import com.heima.wemedia.mapper.WmChannelMapper;
import com.heima.wemedia.mapper.WmUserMapper;
import com.heima.wemedia.service.WmChannelService;
import com.heima.wemedia.service.WmUserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WemediaClient implements IWemediaClient {

    @Autowired
    private WmUserService wmUserService;

    @Autowired
    private WmUserMapper wmUserMapper;

    @Override
    @GetMapping("/api/v1/user/findUserByName/{name}")
    public WmUser findUserByName(@PathVariable("name") String name){
        return wmUserMapper.selectOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
    }


    @Override
    @PostMapping("/api/v1/user/save")
    public ResponseResult wmUserSave(@RequestBody WmUser wmUser) {
        return wmUserService.wmUserSave(wmUser);
    }


    @Autowired
    private WmChannelService wmChannelService;

    /**
     * 获取频道列表
     * @return
     */
    @Override
    @GetMapping("/api/v1/channel/list")
    public ResponseResult getChannels() {
        return wmChannelService.findAll();
    }


}
